package com.zja.service.Impl;

import com.zja.dao.ArticleViewHistoryDao;
import com.zja.dao.Impl.ArticleViewHistoryDaoImpl;
import com.zja.model.ArticleViewHistory;
import com.zja.service.ArticleViewHistoryService;

import java.util.List;

/**
 * @author JA
 * @date: 2025/5/6
 * description:
 */
public class ArticleViewHistoryServiceImpl implements ArticleViewHistoryService {
    private final ArticleViewHistoryDao viewHistoryDao = new ArticleViewHistoryDaoImpl();

    @Override
    public List<ArticleViewHistory> getViewRecordsOfMyArticles(Long authorId, int page, int pageSize) {
        int offset = (page - 1) * pageSize;
        return viewHistoryDao.selectViewRecordsOfMyArticles(authorId, offset, pageSize);
    }

    @Override
    public int countViewRecordsOfMyArticles(Long authorId) {
        return viewHistoryDao.countViewRecordsOfMyArticles(authorId);
    }

    @Override
    public boolean deleteViewRecordById(Long recordId, Long authorId) {
        return viewHistoryDao.deleteViewRecordById(recordId, authorId);
    }

    @Override
    public int deleteAllViewRecordsOfMyArticles(Long authorId) {
        int count = viewHistoryDao.countViewRecordsOfMyArticles(authorId);
        boolean success = viewHistoryDao.deleteAllViewRecordsOfMyArticles(authorId);
        return success ? count : 0;
    }
}
